package boot

import (
	"web/conf"
	"web/controller"
	"web/global"
	"web/middleware"

	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/redis"
)

func InitRouters() {
	store, err := redis.NewStore(20, "tcp", conf.Redis_Ip_Port, "", []byte("session"))
	if err != nil {
		panic(err)
	}
	r1 := global.GlobalServer.Group("/api/v1.0")
	{
		//路由规范
		r1.GET("/areas", controller.GetArea)
		r1.GET("/imagecode/:uuid", controller.GetImageCd)
		r1.GET("/smscode/:mobile", controller.GetSmscd)
		r1.POST("/users", controller.PostRet)

		//登录业务   路由过滤器   中间件
		r1.Use(sessions.Sessions("mysession", store))
		r1.POST("/sessions", controller.PostLogin)
		r1.GET("/session", controller.GetSession)
		//路由过滤器   登录的情况下才能执行一下路由请求
		r1.Use(middleware.Filter)
		r1.DELETE("/session", controller.DeleteSession)
		r1.GET("/user", controller.GetUserInfo)
		r1.PUT("/user/name", controller.PutUserInfo)

		r1.POST("/user/avatar", controller.PostAvatar)
		r1.POST("/user/auth", controller.PutUserAuth)
		r1.GET("/user/auth", controller.GetUserInfo)

		//获取已发布房源信息
		r1.GET("/user/houses", controller.GetUserHouses)

		//发布房源
		r1.POST("/houses", controller.PostHouses)

		//添加房源图片
		r1.POST("/houses/:id/images", controller.PostHousesImage)
		//展示房屋详情
		r1.GET("/houses/:id", controller.GetHouseInfo)
		//展示首页轮播图
		r1.GET("/house/index", controller.GetIndex)
		//搜索房屋
		r1.GET("/houses", controller.GetHouses)
		//下订单
		r1.POST("/orders", controller.PostOrders)
		//获取订单
		r1.GET("/user/orders", controller.GetUserOrder)
		//同意/拒绝订单
		r1.PUT("/orders/:id/status", controller.PutOrders)
	}
}
